package com.runa.monitor.platinterface.platInterface;

import com.runa.monitor.platinterface.platService.InterfaceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("comm")
public class NewCommController {
    @Resource
    private InterfaceService interfaceService;

    @GetMapping("liuhailong/test")
    public String readFmuNow() {
        return "okokokok";
    }

//    @PostMapping("readFmuNow/{identity}/{taskNo}")
//    public Result readFmuNow(@PathVariable String identity, @PathVariable String taskNo) {
//        log.info("计量请求—立即抄表 唯一设备号：{}, 任务号：{}", identity, taskNo);
//        Result result = interfaceService.readFmuNow(identity, taskNo, "");
//        return result;
//    }
//
//    @PostMapping("sentEquArchive/{identity}/{taskNo}")
//    public void sentEquArchive(@PathVariable String identity, @PathVariable String taskNo, @RequestBody List<RunaEquArchive> archives) {
//        log.info("计量请求—网络设备下发档案开始  唯一设备号：{}, 档案信息：{}, 任务号：{}", identity, JSONArray.toJSONString(archives), taskNo);
//        interfaceService.rccSentEquArchive(identity, taskNo, archives, "");
//    }
//
//    @PostMapping("clearEquArchive/{identity}/{taskNo}")
//    public void clearEquArchive(@PathVariable String identity, @PathVariable String taskNo) {
//        log.info("计量请求—清除档案  唯一设备号：{}, 任务号：{}", identity, taskNo);
//        interfaceService.rccClearEquArchive(identity, taskNo, "");
//    }
//
//    @PostMapping("readEquArchive/{identity}/{taskNo}")
//    public void readEquArchive(@PathVariable String identity, @PathVariable String taskNo, @RequestParam List<Integer> indexes) {
//        log.info("计量请求—网络设备读档案  唯一设备号：{}, 测点号：{}, 任务号：{}", identity, indexes, taskNo);
//        interfaceService.readEquArchive(identity, taskNo, indexes, "");
//    }
//
//    @PostMapping("setReadPeriod/{identity}/{taskNo}")
//    public void setReadPeriod(@PathVariable String identity, @PathVariable String taskNo, @RequestBody GatewayDeviceParameter gatewayDeviceParameter) {
//        log.info("计量请求—网络设备设定抄读周期  唯一设备号：{}, 周期：{}, 任务号：{}", identity, gatewayDeviceParameter, taskNo);
//        interfaceService.setMeterReadingCycleParameter(identity, taskNo, gatewayDeviceParameter, "");
//    }
//
//    @PostMapping("readReadPeriod/{identity}/{taskNo}")
//    public void readReadPeriod(@PathVariable String identity, @PathVariable String taskNo) {
//        log.info("计量请求—网络设备读抄读周期  唯一设备号：{}, 任务号：{}", identity, taskNo);
//        interfaceService.readMeterReadingCycleParameter(identity, taskNo, "");
//    }
//
//    @PostMapping("flowLimit/{identity}/{taskNo}")
//    public void flowLimit(@PathVariable String identity, @PathVariable String taskNo, Float value, Boolean priority) {
//        log.info("计量请求—网络设备流量超限设定  唯一设备号：{}, 任务号：{}", identity, taskNo);
//        interfaceService.flowLimitSetting(identity, taskNo, value,priority,"");
//    }
//
//    @Resource(name = "asyncRequestScheduler")
//    private Executor executor;
//
//    @PostMapping("readMeter/{taskNo}")
//    public void readMeter(@PathVariable String taskNo,
//                          @RequestParam("meterSerial") List<String> meterSerial) {
//        log.info("计量请求—抄表  表唯一号：{}, 任务号：{}", meterSerial, taskNo);
//        executor.execute(() -> {
//            interfaceService.rccReadNodeData(taskNo, "", meterSerial, EquData.EquDataType.METER);
//        });
//    }
//
//    private static Integer i=1;
//
//    @PostMapping("readValve/{taskNo}")
//    public void readValve( @PathVariable String taskNo,
//                          @RequestParam("valveSerial") List<String> valveSerial) {
//        log.info("计量请求—抄阀 阀编号：{}, 任务号：{}", valveSerial, taskNo);
////        if (i++==1){
////            try {
////                Thread.sleep(400000);
////            } catch (InterruptedException e) {
////                
////            }
////        }
//        interfaceService.rccReadNodeData(taskNo, "", valveSerial, EquData.EquDataType.VALVE);
//    }
//
//    @PostMapping("readBuildValve/{taskNo}")
//    public void readBuildValve( @PathVariable String taskNo,
//                               @RequestParam("valveSerial") List<String> valveSerial) {
//        log.info("计量请求—抄楼站阀  阀编号：{}, 任务号：{}", valveSerial, taskNo);
//        interfaceService.rccReadNodeData(taskNo, "", valveSerial, EquData.EquDataType.PUBLIC_UNIT);
//    }
//
//    @PostMapping("readPanel/{taskNo}")
//    public void readPanel( @PathVariable String taskNo,
//                          @RequestParam("panelSerial") List<String> panelSerial) {
//        log.info("计量请求—抄温度面板  面板编号：{}, 任务号：{}", panelSerial, taskNo);
//        interfaceService.rccReadNodeData(taskNo, "", panelSerial, EquData.EquDataType.TEMPERATURE_PANEL);
//    }
//
//    @PostMapping("valveOnOffControl/{identity}/{taskNo}")
//    public void valveOnOffControl(@PathVariable String identity,
//                                  @PathVariable String taskNo,
//                                  @RequestParam("valveSerial") List<String> valveSerial,
//                                  Boolean ifLock, Integer opening) {
//        log.info("计量请求—户阀通断控制  网络设备编号：{}, 阀编号：{}, 锁定：{}, 开度：{}, 任务号：{}", identity, valveSerial, ifLock, opening, taskNo);
////        interfaceService.valveOnOffControl(identity, taskNo, valveSerial, ifLock, opening, "");
//    }
//
//    @PostMapping("valveTemperatureControl/{identity}/{taskNo}")
//    public void valveTemperatureControl(@PathVariable String identity,
//                                        @PathVariable String taskNo,
//                                        @RequestParam List<String> valveSerial, Float temperature,
//                                        Boolean ifLock, Float temperatureUp, Float temperatureDown) {
//        log.info("计量请求—户阀温度控制  " +
//                        "网络设备编号：{}, 阀编号：{}, 温度：{}, 锁定：{}, 上限：{}, 下限：{}, 任务号：{}",
//                identity, valveSerial, temperature, ifLock, temperatureUp, temperatureDown, taskNo);
////        interfaceService.valveTemperatureControl(identity, taskNo, valveSerial, temperature, ifLock, temperatureUp, temperatureDown, "");
//    }
//
//    @PostMapping("valveTemperatureComp/{identity}/{taskNo}")
//    public void valveTemperatureComp(
//                                     @PathVariable String taskNo,
//                                     @RequestParam String valveSerial, Float compensation) {
//        log.info("计量请求—户阀温度补偿  " +
//                " 阀编号：{}, 补偿值：{}, 任务号：{}", valveSerial, compensation, taskNo);
//        interfaceService.valveTemperatureComp( taskNo, "", valveSerial, compensation);
//    }
//
//    @PostMapping("buildValveControl/{identity}/{taskNo}")
//    public void buildValveControl(@PathVariable String taskNo,
//                                  @RequestBody List<ValveControl> valveControlList) {
//        log.info("计量请求—楼站阀门控制  阀门编号：{}, 控制模式：{}, 控制参数：{}, 任务号：{}", valveControlList);
//        interfaceService.buildValveControl(taskNo, "", valveControlList);
//    }
//
//
//    @PostMapping("buildValveParam/{taskNo}")
//    public void buildValveParam(@PathVariable String taskNo,
//                                Integer model, List<String> valves) {
//        log.info("计量请求—读楼站阀门参数  阀门编号：{}, 参数类型：{}, 任务号：{}", valves, model, taskNo);
//        for (String valve : valves) {
//            interfaceService.buildValveParam(taskNo, valve, model,"");
//        }
//
//    }
//
//    @PostMapping("buildValveModel/{identity}/{taskNo}")
//    public void buildValveModel(@PathVariable String taskNo,
//                                @RequestParam boolean model,
//                                @RequestParam String valveSerial) {
//        log.info("计量请求—楼站阀门模式修改 阀门编号：{}, 模式：{}, 任务号：{}", valveSerial, model, taskNo);
//        interfaceService.buildValveModel(taskNo,"",  valveSerial, model);
//    }

//    @SneakyThrows
//    @PostMapping("ceshi")
//    public void ceshi(@RequestParam String taskNo) {
//        Class<InterfaceService> interfaceServiceClass = InterfaceService.class;
//        Method[] methods = interfaceServiceClass.getMethods();
//        String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
//        for (Method method : methods) {
//            if (method.getName().equalsIgnoreCase("readFmuNow")){
//                method.invoke(interfaceServiceClass.newInstance(),"12515","fff","ff");
//            }
//        }
//
//    }
}
